package com.artqiyi.dollmachine.views.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.artqiyi.dollmachine.R;
import com.artqiyi.dollmachine.common.constant.Constant;
import com.artqiyi.dollmachine.model.entity.DollBean;
import com.artqiyi.dollmachine.utils.GlideRoundImage;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.FitCenter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/10/30 0030.
 */

public class DollAdapter extends BaseQuickAdapter<DollBean, BaseViewHolder>{

    public DollAdapter(@Nullable List<DollBean> data) {
        super(R.layout.item_doll, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DollBean item) {
        helper.setText(R.id.tvName, item.getWare_name());
        helper.setText(R.id.tvDeviceName, item.getName());
        helper.setText(R.id.tvCoin, String.format(mContext.getString(R.string.operate_coin_every_time), String.valueOf(item.getCoin())));
        helper.getView(R.id.tvStatus).setBackgroundResource(getBackground(item.getDevice_status()));
        helper.setText(R.id.tvStatus, getStatus(item.getDevice_status()));
        Glide.with(mContext).load(item.getWare_image()).placeholder(R.mipmap.img_fail).fitCenter().into((ImageView) helper.getView(R.id.imgDoll));
    }

    private String getStatus(int status) {
        String statusStr = null;
        if (status == Constant.STATUS_FREE) {
            statusStr = mContext.getResources().getString(R.string.game_free);
        } else if (status == Constant.STATUS_PLAYING) {
            statusStr = mContext.getResources().getString(R.string.game_playing);
        } else if (status == Constant.STATUS_BREAKDOWN) {
            statusStr = mContext.getResources().getString(R.string.game_breakdown);
        }
        return statusStr;
    }

    private int getBackground(int status) {
        int imgStatus = 0;
        if (status == Constant.STATUS_FREE) {
            imgStatus = R.drawable.round_green_bg;
        } else if (status == Constant.STATUS_PLAYING) {
            imgStatus = R.drawable.round_orange_bg;
        } else if (status == Constant.STATUS_BREAKDOWN) {
            imgStatus = R.drawable.round_red_bg;
        }
        return imgStatus;
    }

}
